/**
 * 
 */
package com.elite.groovy.callback

import groovy.json.* //导入grooby的json解析api包
import java.util.Map;
import com.elite.groovy.util.EliteBean;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.wisdge.utils.RandomUtils;
import com.elite.groovy.util.Util;
import net.sf.json.JSONObject;
import net.sf.json.JSONArray;
import cn.com.elite.PropertiesUtil;
/**
 * @author luper
 *
 */
public class VasReportHFCreate implements ServiceBackInvoke {
	private static final Log log=LogFactory.getLog(VasReportHFCreate.class);
		private String charset = "utf-8"; //设置字符集
	private int timeout = 100000; //设置请求超时时间
	private int enableSSLflag = 0;	
	public String doCallBack(EliteBean eliteBean, HttpServletRequest request, HttpServletResponse response){

		//当前时间，任务生成限时判断
		def querysql1="select to_number(to_char(sysdate,'hh24')) nowhour from dual";
		def nowhour="";
		def list1=eliteBean.chaxun_sql(querysql1,"dataSource");
		log.debug("list1-------------------------------"+list1);
		for(def i=0;i<list1.size();i++){
			def map1=list1[i];
			int v_nowhour=map1.get("nowhour");	  
			log.debug("v_nowhour---v_nowhour-----v_nowhour----"+v_nowhour);
			def updatesqlresult2,isvip;

	/**
	 * 报案回访
	 */		
			
			log.debug("报案回访数据开始生成！");
			log.debug("报案未回访数据提前打标");
			def updatesql1="update OBT_BUS_LIST set TASKSTATUS=3 where bus_type in('DDE','DDF') and TASKSTATUS=0 and to_date(substr(batch,1,14),'yyyy-mm-dd hh24:mi:ss')<= to_date(to_char(sysdate -1/24,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss') ";
			def updatesqlresult1=eliteBean.update(updatesql1,"dataSource");
			log.debug("updatesqlresult1:"+updatesqlresult1);
			
			log.debug("判断是不是内部员工,如果是直接生成回访，如果不是，推送智能外呼");	
			log.debug("现场报案插入中间表,，，，");
			
			//TASKSTATUS=0 待发送，TASKSTATUS=3 直接生成回访
			
			def relist=eliteBean.chaxun_sql("select sysguid as vguid,sysguid as oguid, str_M ,0 as flag,'REPORT' as obtype,to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') as curdate,'','36EPKD' as mapid,'DDF' as btype,LINKER_PHONE,linker_name,r.policy_no from OBT_BUS_LIST l left join DH_REPORT r on r.CLM_NO=l.str_M where bus_type ='DDF' and to_date(substr(batch,1,14),'yyyy-mm-dd hh24:mi:ss') <=to_char(sysdate -1/24,'yyyy-mm-dd hh24:mi:ss') and TASKSTATUS=3 and (r.SELF_CLAIM_FLAG!='1' OR r.SELF_CLAIM_FLAG IS NULL)","dataSource");
			
			if(relist.size()>0){
				for(def j=0;j<relist.size();j++){
					isvip=doselete(relist[j].get("policy_no"),relist[j].get("LINKER_PHONE"),eliteBean,relist[j].get("linker_name"),charset,timeout,enableSSLflag);
					
					//B开头平安保单直接人工回访
					def policy_no1 = relist[j].get("policy_no");
					
					if(isvip=="2"&&policy_no1.substring(0,1)!="B"){
						//20230323   转机器人
						//插入待发送回访数据
						updatesqlresult2=eliteBean.update("insert into Ob_visitTask(VISITTASK_GUID,OBJECTIVE_GUID,BUSINESSNO,TASKSTATUS,BUSTYPE, CREATEDDATE, CREATEDBY,MAP_ID,BUSTYPE_REPORT)values('"+relist[j].get("vguid")+"','"+relist[j].get("oguid")+"','"+relist[j].get("str_M")+"',0,'"+relist[j].get("obtype")+"',to_date('"+relist[j].get("curdate")+"','yyyy-mm-dd hh24:mi:ss'),'','"+relist[j].get("mapid")+"','"+relist[j].get("btype")+"')","dataSource");
						
						//20220601  胡啟滨提出现场报案回访全改人工回访
						/*updatesqlresult2=eliteBean.update("insert into Ob_visitTask(VISITTASK_GUID,OBJECTIVE_GUID,BUSINESSNO,TASKSTATUS,BUSTYPE, CREATEDDATE, CREATEDBY,MAP_ID,BUSTYPE_REPORT,CALLLOSE)values('"+relist[j].get("vguid")+"','"+relist[j].get("oguid")+"','"+relist[j].get("str_M")+"',1,'"+relist[j].get("obtype")+"',to_date('"+relist[j].get("curdate")+"','yyyy-mm-dd hh24:mi:ss'),'','"+relist[j].get("mapid")+"','"+relist[j].get("btype")+"',1)","dataSource")
						def custid=eliteBean.chaxun_sql("select customer_guid from(select customer_guid from CUSTOMER c  where mobile= '"+relist[j].get("LINKER_PHONE")+"' and stringfield18 = '"+relist[j].get("policy_no")+"' order by MODIFIEDDATE desc) where rownum=1","dataSource")
						if(custid.size()>0){
							def listtemp=custid[0]
							isvip = listtemp.get("customer_guid")
						}else{
							def cguid=Util.getGuid()
							eliteBean.update("insert into customer(CUSTOMER_GUID,customertype_id,CUSTOMERNAME,MOBILE,stringfield18,createddate,createdby,MODIFIEDDATE,MODIFIEDBY)values('"+cguid+"','KFjoin','"+relist[j].get("linker_name")+"','"+relist[j].get("LINKER_PHONE")+"','"+relist[j].get("policy_no")+"',sysdate,'SELITE',sysdate,'SELITE')","dataSource")
							isvip = cguid
						}
						//生成 objective
						def updatesql45="insert into objective (OBJECTIVE_GUID, OBJECTIVETYPE_ID, HANDLEGROUP_ID,PRIORITY_ID,EXPIREDDATE,CUSTOMER_GUID,OBJECTIVESTATUS,CREATEDDATE,CREATEDBY,WORKORDERFRAME_ID,OBJECTIVESUBSTATUS,MAP_ID,CURSTEP_ID_MAP)select objective_guid,'USZP59','ORG016','NORMAL',sysdate,'"+isvip+"','OPEN',CREATEDDATE,CREATEDBY,map_id,'OPEN',map_id,'UUANWS' from Ob_visitTask where visittask_guid='"+relist[j].get("vguid")+"'"
						def updatesqlresult45=eliteBean.update(updatesql45,"dataSource")
						//生成 elitetask 
						def updatesql46="insert into elitetask (ELITETASK_GUID, OBJECTIVE_GUID, OBJECTIVETYPE_ID, EXPECTSTARTTIME,OBSTATUS,PRIORITY, HANDLEGROUP_ID, CREATEDBY, CREATEDDATE,CUSTOMER_GUID,CURSTEPSTATUS,CURSTEP_ID_MAP,MAP_ID,OBJECTIVESUBSTATUS,ELITETASKSTATUS, OBFLAG) select sysguid,objective_guid,'USZP59',sysdate,'OPEN','NORMAL','ORG016',CREATEDBY,CREATEDDATE,'"+isvip+"','OPEN','UUANWS',MAP_ID,'OPEN','OPEN','1' FROM Ob_visitTask where visittask_guid='"+relist[j].get("vguid")+"'"
						def updatesqlresult46=eliteBean.update(updatesql46,"dataSource")*/
					}else{
						//插入直接生成回访数据
						updatesqlresult2=eliteBean.update("insert into Ob_visitTask(VISITTASK_GUID,OBJECTIVE_GUID,BUSINESSNO,TASKSTATUS,BUSTYPE, CREATEDDATE, CREATEDBY,MAP_ID,BUSTYPE_REPORT)values('"+relist[j].get("vguid")+"','"+relist[j].get("oguid")+"','"+relist[j].get("str_M")+"',3,'"+relist[j].get("obtype")+"',to_date('"+relist[j].get("curdate")+"','yyyy-mm-dd hh24:mi:ss'),'','"+relist[j].get("mapid")+"','"+relist[j].get("btype")+"')","dataSource");				

						//生成 objective
						def updatesql45="insert into objective (OBJECTIVE_GUID, OBJECTIVETYPE_ID, HANDLEGROUP_ID,PRIORITY_ID,EXPIREDDATE,CUSTOMER_GUID,OBJECTIVESTATUS,CREATEDDATE,CREATEDBY,WORKORDERFRAME_ID,OBJECTIVESUBSTATUS,MAP_ID,CURSTEP_ID_MAP)select objective_guid,'USZP59','ORG016','NORMAL',sysdate,'"+isvip+"','OPEN',CREATEDDATE,CREATEDBY,map_id,'OPEN',map_id,'UUANWS' from Ob_visitTask where visittask_guid='"+relist[j].get("vguid")+"'";
						  
						def updatesqlresult45=eliteBean.update(updatesql45,"dataSource");
						log.debug("updatesqlresult45:"+updatesqlresult45);
						//生成 elitetask 
						def updatesql46="insert into elitetask (ELITETASK_GUID, OBJECTIVE_GUID, OBJECTIVETYPE_ID, EXPECTSTARTTIME,OBSTATUS,PRIORITY, HANDLEGROUP_ID, CREATEDBY, CREATEDDATE,CUSTOMER_GUID,CURSTEPSTATUS,CURSTEP_ID_MAP,MAP_ID,OBJECTIVESUBSTATUS,ELITETASKSTATUS, OBFLAG) select sysguid,objective_guid,'USZP59',sysdate,'OPEN','NORMAL','ORG016',CREATEDBY,CREATEDDATE,'"+isvip+"','OPEN','UUANWS',MAP_ID,'OPEN','OPEN','1' FROM Ob_visitTask where visittask_guid='"+relist[j].get("vguid")+"'";
						def updatesqlresult46=eliteBean.update(updatesql46,"dataSource");
						log.debug("updatesqlresult46:"+updatesqlresult46);		
						
					}

				}
				
				
			}
			
			log.debug("报案非现场未回访数据，已打标插入待回访中间表");
			def relist2=eliteBean.chaxun_sql("select sysguid as vguid,sysguid as oguid, str_M ,0,'REPORT' as obtype,to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') as curdate,'','USYCAB' as mapid,'DDE' as btype,LINKER_PHONE,linker_name, r.policy_no from OBT_BUS_LIST l left join DH_REPORT r on r.CLM_NO=l.str_M where bus_type ='DDE' and to_date(substr(batch,1,14),'yyyy-mm-dd hh24:mi:ss') <=to_char(sysdate -1/24,'yyyy-mm-dd hh24:mi:ss') and TASKSTATUS=3 and (r.SELF_CLAIM_FLAG!='1' OR r.SELF_CLAIM_FLAG IS NULL)","dataSource");
			if(relist2.size()>0){
				for(def k=0;k<relist2.size();k++){
					isvip=doselete(relist2[k].get("policy_no"),relist2[k].get("LINKER_PHONE"),eliteBean,relist2[k].get("linker_name"),charset,timeout,enableSSLflag);
					
					//B开头平安保单直接人工回访
					def policy_no2 = relist2[k].get("policy_no");
					
					if(isvip=="2"&&policy_no2.substring(0,1)!="B"){
						//插入待回访数据
						updatesqlresult2=eliteBean.update("insert into Ob_visitTask(VISITTASK_GUID,OBJECTIVE_GUID,BUSINESSNO,TASKSTATUS,BUSTYPE, CREATEDDATE, CREATEDBY,MAP_ID,BUSTYPE_REPORT)values('"+relist2[k].get("vguid")+"','"+relist2[k].get("oguid")+"','"+relist2[k].get("str_M")+"',0,'"+relist2[k].get("obtype")+"',to_date('"+relist2[k].get("curdate")+"','yyyy-mm-dd hh24:mi:ss'),'','"+relist2[k].get("mapid")+"','"+relist2[k].get("btype")+"')","dataSource");				
					}else{
						//插入直接生成回访数据
						updatesqlresult2=eliteBean.update("insert into Ob_visitTask(VISITTASK_GUID,OBJECTIVE_GUID,BUSINESSNO,TASKSTATUS,BUSTYPE, CREATEDDATE, CREATEDBY,MAP_ID,BUSTYPE_REPORT)values('"+relist2[k].get("vguid")+"','"+relist2[k].get("oguid")+"','"+relist2[k].get("str_M")+"',3,'"+relist2[k].get("obtype")+"',to_date('"+relist2[k].get("curdate")+"','yyyy-mm-dd hh24:mi:ss'),'','"+relist2[k].get("mapid")+"','"+relist2[k].get("btype")+"')","dataSource");				

						 //生成 objective
					  def updatesql451="insert into objective (OBJECTIVE_GUID, OBJECTIVETYPE_ID, HANDLEGROUP_ID,PRIORITY_ID,EXPIREDDATE,CUSTOMER_GUID,OBJECTIVESTATUS,CREATEDDATE,CREATEDBY,WORKORDERFRAME_ID,OBJECTIVESUBSTATUS,MAP_ID,CURSTEP_ID_MAP)select objective_guid,'USZP59','ORG016','NORMAL',sysdate,'"+isvip+"','OPEN',CREATEDDATE,CREATEDBY,map_id,'OPEN',map_id,'B51UT0' from Ob_visitTask where visittask_guid='"+relist2[k].get("vguid")+"'";
					  
					  def updatesqlresult451=eliteBean.update(updatesql451,"dataSource");
					  log.debug("updatesqlresult451:"+updatesqlresult451);
						//生成 elitetask 
					  def updatesql461="insert into elitetask (ELITETASK_GUID, OBJECTIVE_GUID, OBJECTIVETYPE_ID, EXPECTSTARTTIME,OBSTATUS,PRIORITY, HANDLEGROUP_ID, CREATEDBY, CREATEDDATE,CUSTOMER_GUID,CURSTEPSTATUS,CURSTEP_ID_MAP,MAP_ID,OBJECTIVESUBSTATUS,ELITETASKSTATUS, OBFLAG) select sysguid,objective_guid,'USZP59',sysdate,'OPEN','NORMAL','ORG016',CREATEDBY,CREATEDDATE,'"+isvip+"','OPEN','B51UT0',MAP_ID,'OPEN','OPEN','1' FROM Ob_visitTask where visittask_guid='"+relist2[k].get("vguid")+"'";
					  def updatesqlresult461=eliteBean.update(updatesql461,"dataSource");
					  log.debug("updatesqlresult461:"+updatesqlresult461);		
						
					}

				}
				
				
			}
			
			
			log.debug("报案自助理赔未回访数据，已打标插入待回访中间表");
			def relist3=eliteBean.chaxun_sql("select sysguid as vguid,sysguid as oguid, str_M ,0,'REPORT' as obtype,to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') as curdate,'','D41PUA' as mapid,'ZZLP' as btype,LINKER_PHONE,linker_name,r.policy_no policy_no from OBT_BUS_LIST l left join DH_REPORT r on r.CLM_NO=l.str_M where  TASKSTATUS=3 and to_date(substr(batch,1,14),'yyyy-mm-dd hh24:mi:ss') <=to_char(sysdate -1/24,'yyyy-mm-dd hh24:mi:ss') and r.SELF_CLAIM_FLAG='1'","dataSource");
			if(relist3.size()>0){
				for(def y=0;y<relist3.size();y++){
					isvip=doselete(relist3[y].get("policy_no"),relist3[y].get("LINKER_PHONE"),eliteBean,relist3[y].get("linker_name"),charset,timeout,enableSSLflag);
					
					//B开头平安保单直接人工回访
					def policy_no3 = relist3[y].get("policy_no");
					
					if(isvip=="2"&&policy_no3.substring(0,1)!="B"){
						//20230323  转机器人
						//插入待回访数据
						updatesqlresult2=eliteBean.update("insert into Ob_visitTask(VISITTASK_GUID,OBJECTIVE_GUID,BUSINESSNO,TASKSTATUS,BUSTYPE, CREATEDDATE, CREATEDBY,MAP_ID,BUSTYPE_REPORT)values('"+relist3[y].get("vguid")+"','"+relist3[y].get("oguid")+"','"+relist3[y].get("str_M")+"',0,'"+relist3[y].get("obtype")+"',to_date('"+relist3[y].get("curdate")+"','yyyy-mm-dd hh24:mi:ss'),'','"+relist3[y].get("mapid")+"','"+relist3[y].get("btype")+"')","dataSource");
						
						//20220610  车险部李剑经理提出自助视频查勘报案回访全改人工回访
						/*updatesqlresult2=eliteBean.update("insert into Ob_visitTask(VISITTASK_GUID,OBJECTIVE_GUID,BUSINESSNO,TASKSTATUS,BUSTYPE, CREATEDDATE, CREATEDBY,MAP_ID,BUSTYPE_REPORT,CALLLOSE)values('"+relist3[y].get("vguid")+"','"+relist3[y].get("oguid")+"','"+relist3[y].get("str_M")+"',1,'"+relist3[y].get("obtype")+"',to_date('"+relist3[y].get("curdate")+"','yyyy-mm-dd hh24:mi:ss'),'','"+relist3[y].get("mapid")+"','"+relist3[y].get("btype")+"',1)","dataSource")
						def custid=eliteBean.chaxun_sql("select customer_guid from(select customer_guid from CUSTOMER c  where mobile= '"+relist3[y].get("LINKER_PHONE")+"' and stringfield18 = '"+relist3[y].get("policy_no")+"' order by MODIFIEDDATE desc) where rownum=1","dataSource")
						if(custid.size()>0){
							def listtemp=custid[0]
							isvip = listtemp.get("customer_guid")
						}else{
							def cguid=Util.getGuid()
							eliteBean.update("insert into customer(CUSTOMER_GUID,customertype_id,CUSTOMERNAME,MOBILE,stringfield18,createddate,createdby,MODIFIEDDATE,MODIFIEDBY)values('"+cguid+"','KFjoin','"+relist3[y].get("linker_name")+"','"+relist3[y].get("LINKER_PHONE")+"','"+relist3[y].get("policy_no")+"',sysdate,'SELITE',sysdate,'SELITE')","dataSource")
							isvip = cguid
						}
						//生成 objective
						def updatesql45="insert into objective (OBJECTIVE_GUID, OBJECTIVETYPE_ID, HANDLEGROUP_ID,PRIORITY_ID,EXPIREDDATE,CUSTOMER_GUID,OBJECTIVESTATUS,CREATEDDATE,CREATEDBY,WORKORDERFRAME_ID,OBJECTIVESUBSTATUS,MAP_ID,CURSTEP_ID_MAP)select objective_guid,'USZP59','ORG016','NORMAL',sysdate,'"+isvip+"','OPEN',CREATEDDATE,CREATEDBY,map_id,'OPEN',map_id,'R41IZC' from Ob_visitTask where visittask_guid='"+relist3[y].get("vguid")+"'"
						def updatesqlresult45=eliteBean.update(updatesql45,"dataSource")
						//生成 elitetask 
						def updatesql46="insert into elitetask (ELITETASK_GUID, OBJECTIVE_GUID, OBJECTIVETYPE_ID, EXPECTSTARTTIME,OBSTATUS,PRIORITY, HANDLEGROUP_ID, CREATEDBY, CREATEDDATE,CUSTOMER_GUID,CURSTEPSTATUS,CURSTEP_ID_MAP,MAP_ID,OBJECTIVESUBSTATUS,ELITETASKSTATUS, OBFLAG) select sysguid,objective_guid,'USZP59',sysdate,'OPEN','NORMAL','ORG016',CREATEDBY,CREATEDDATE,'"+isvip+"','OPEN','R41IZC',MAP_ID,'OPEN','OPEN','1' FROM Ob_visitTask where visittask_guid='"+relist3[y].get("vguid")+"'"
						def updatesqlresult46=eliteBean.update(updatesql46,"dataSource")*/
					}else{
						//插入直接生成回访数据
						updatesqlresult2=eliteBean.update("insert into Ob_visitTask(VISITTASK_GUID,OBJECTIVE_GUID,BUSINESSNO,TASKSTATUS,BUSTYPE, CREATEDDATE, CREATEDBY,MAP_ID,BUSTYPE_REPORT)values('"+relist3[y].get("vguid")+"','"+relist3[y].get("oguid")+"','"+relist3[y].get("str_M")+"',3,'"+relist3[y].get("obtype")+"',to_date('"+relist3[y].get("curdate")+"','yyyy-mm-dd hh24:mi:ss'),'','"+relist3[y].get("mapid")+"','"+relist3[y].get("btype")+"')","dataSource");				

						 //生成 objective
					  def updatesql452="insert into objective (OBJECTIVE_GUID, OBJECTIVETYPE_ID, HANDLEGROUP_ID,PRIORITY_ID,EXPIREDDATE,CUSTOMER_GUID,OBJECTIVESTATUS,CREATEDDATE,CREATEDBY,WORKORDERFRAME_ID,OBJECTIVESUBSTATUS,MAP_ID,CURSTEP_ID_MAP)select objective_guid,'USZP59','ORG016','NORMAL',sysdate,'"+isvip+"','OPEN',CREATEDDATE,CREATEDBY,map_id,'OPEN',map_id,'R41IZC' from Ob_visitTask where visittask_guid='"+relist3[y].get("vguid")+"'";
					  
					  def updatesqlresult452=eliteBean.update(updatesql452,"dataSource");
					  log.debug("updatesqlresult452:"+updatesqlresult452);
						//生成 elitetask 
					  def updatesql462="insert into elitetask (ELITETASK_GUID, OBJECTIVE_GUID, OBJECTIVETYPE_ID, EXPECTSTARTTIME,OBSTATUS,PRIORITY, HANDLEGROUP_ID, CREATEDBY, CREATEDDATE,CUSTOMER_GUID,CURSTEPSTATUS,CURSTEP_ID_MAP,MAP_ID,OBJECTIVESUBSTATUS,ELITETASKSTATUS, OBFLAG) select sysguid,objective_guid,'USZP59',sysdate,'OPEN','NORMAL','ORG016',CREATEDBY,CREATEDDATE,'"+isvip+"','OPEN','R41IZC',MAP_ID,'OPEN','OPEN','1' FROM Ob_visitTask where visittask_guid='"+relist3[y].get("vguid")+"'";
					  def updatesqlresult462=eliteBean.update(updatesql462,"dataSource");
					  log.debug("updatesqlresult462:"+updatesqlresult462);		
						
					}

				}
				
				
			}				
			
			log.debug("报案已写入待回访中间表更新状态");
			def updatesql11="update OBT_BUS_LIST set TASKSTATUS=2 where TASKSTATUS=3 and bus_type in('DDE','DDF')";
			def updatesqlresult11=eliteBean.update(updatesql11,"dataSource");
			log.debug("updatesqlresult11:"+updatesqlresult11);        
	/**
	 * 增值回访
	 */		if(v_nowhour>=8&&v_nowhour<=20)	{
	 
			log.debug("增值回访数据开始生成！");
			log.debug("增值默认推送智能外呼系的未回访数据提前打标");
			def updatesql5="update objective set realvisiter_flag='3' where objective_guid in(select objective_guid from objective o left join tabcdh_vas_list t on t.relation_id=o.objective_guid where o.realvisiter_flag in ('0','1') and o.CURSTEP_ID_MAP in('KC17US','0P9U5U','LXO49V','OEADRX') and o.OBJECTIVESTATUS='OPEN' and t.schedul_type in ('0','1','2') and TO_CHAR(o.createddate,'yyyy-mm-dd hh24:mi:ss')<=to_char(sysdate -2/24,'yyyy-mm-dd hh24:mi:ss'))";
			def updatesqlresult5=eliteBean.update(updatesql5,"dataSource");
			log.debug("updatesqlresult5:"+updatesqlresult5);
			
			def relist4=eliteBean.chaxun_sql("select sysguid as vguid,OBJECTIVE_GUID as oguid,WORKORDERID,MAP_ID,'0','VAS' as obtype,to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') as curdate,createdby,calltel,callby,policyno from objective where realvisiter_flag='3' and CURSTEP_ID_MAP in('KC17US','0P9U5U','LXO49V','OEADRX') and OBJECTIVESTATUS='OPEN'","dataSource");
			
			log.debug("relist4.size():"+relist4.size());
			if(relist4.size()>0){
				for(def v1=0;v1<relist4.size();v1++){
					isvip=doselete(relist4[v1].get("policyno"),relist4[v1].get("calltel"),eliteBean,relist4[v1].get("callby"),charset,timeout,enableSSLflag);
					if(isvip=="2"){
						//插入待回访数据
						updatesqlresult2=eliteBean.update("insert into Ob_visitTask(VISITTASK_GUID, OBJECTIVE_GUID, BUSINESSNO, TASKSTATUS,MAP_ID ,BUSTYPE, CREATEDDATE, CREATEDBY)values('"+relist4[v1].get("vguid")+"','"+relist4[v1].get("oguid")+"','"+relist4[v1].get("WORKORDERID")+"',0,'"+relist4[v1].get("MAP_ID")+"','"+relist4[v1].get("obtype")+"',to_date('"+relist4[v1].get("curdate")+"','yyyy-mm-dd hh24:mi:ss'),'"+relist4[v1].get("createdby")+"')","dataSource");				
					}else{
						//插入直接生成回访数据
						updatesqlresult2=eliteBean.update("insert into Ob_visitTask(VISITTASK_GUID, OBJECTIVE_GUID, BUSINESSNO, TASKSTATUS,MAP_ID, BUSTYPE, CREATEDDATE, CREATEDBY)values('"+relist4[v1].get("vguid")+"','"+relist4[v1].get("oguid")+"','"+relist4[v1].get("WORKORDERID")+"',3,'"+relist4[v1].get("MAP_ID")+"','"+relist4[v1].get("obtype")+"',to_date('"+relist4[v1].get("curdate")+"','yyyy-mm-dd hh24:mi:ss'),'"+relist4[v1].get("createdby")+"')","dataSource");				

						  //更新-- 车险增值   OBJECTIVE到回访环节
							  def updatesql2="update objective set realvisiter_flag='1',HANDLEGROUP_ID='ORG016',OBJECTIVESUBSTATUS='',CURSTEP_ID_MAP='D2B8QB' where objective_guid ='"+relist4[v1].get("oguid")+"' and MAP_ID='HWYY20'";
							  def updatesqlresult21=eliteBean.update(updatesql2,"dataSource");
							  log.debug("updatesqlresult21:"+updatesqlresult21);
								//更新-- 非车险增值 OBJECTIVE到回访环节
							  def updatesql3="update objective set realvisiter_flag='1',HANDLEGROUP_ID='ORG016',OBJECTIVESUBSTATUS='',CURSTEP_ID_MAP='JLNKLC' where objective_guid ='"+relist4[v1].get("oguid")+"' and MAP_ID='K3ZK57'";
							  def updatesqlresult3=eliteBean.update(updatesql3,"dataSource");
							  log.debug("updatesqlresult3:"+updatesqlresult3);
								
								//更新-- 车险增值   ELITETASK到回访环节
							  def updatesql4="update elitetask set OBFLAG='1',CURSTEP_ID='D2B8QB',CURSTEP_ID_MAP='D2B8QB',OBJECTIVESUBSTATUS='',HANDLEGROUP_ID='ORG016' where objective_guid = '"+relist4[v1].get("oguid")+"' and MAP_ID='HWYY20'";
							  def updatesqlresult4=eliteBean.update(updatesql4,"dataSource");
							  log.debug("updatesqlresult4:"+updatesqlresult4);		  
								//更新-- 非车险增值 ELITETASK到回访环节
							  def updatesql51="update elitetask set  OBFLAG='1',CURSTEP_ID='JLNKLC',CURSTEP_ID_MAP='JLNKLC',OBJECTIVESUBSTATUS='',HANDLEGROUP_ID='ORG016' where objective_guid ='"+relist4[v1].get("oguid")+"' and MAP_ID='K3ZK57'";
							  def updatesqlresult51=eliteBean.update(updatesql51,"dataSource");
							  log.debug("updatesqlresult51:"+updatesqlresult51);		
						
					}

				}
				
				
			}	
			
			
				
			log.debug("增值已写入待回访中间表更新增值回访状态：回访中");
			def updatesql8="update tabcdh_vas_list set visit_type='1' where relation_id in (select objective_guid from objective where realvisiter_flag='3' and CURSTEP_ID_MAP in('KC17US','0P9U5U','LXO49V','OEADRX') and OBJECTIVESTATUS='OPEN')";
			def updatesqlresult8=eliteBean.update(updatesql8,"dataSource");
			log.debug("updatesqlresult8:"+updatesqlresult8);
			
			log.debug("增值已写入待回访中间表更新状态");
			def updatesql7="update objective set realvisiter_flag='2' where realvisiter_flag='3' and CURSTEP_ID_MAP in('KC17US','0P9U5U','LXO49V','OEADRX') and OBJECTIVESTATUS='OPEN'";
			def updatesqlresult7=eliteBean.update(updatesql7,"dataSource");
			log.debug("updatesqlresult7:"+updatesqlresult7);

			}
	/**
	 * 不满意回访
	 */	       		
			if(v_nowhour>=9&&v_nowhour<=20)	{
				
				//2天内未回访过不满意人工回访+质检数据生成
				def querysql11="select w.rn ,w.a guid,w.b c_createddate ,w.c customer_guid,w.d event_guid,o.objective_guid objective_guid,sysguid objguid,flag from (select ROW_NUMBER() OVER(PARTITION BY PHONENO ORDER BY CREATEDDATE asc) rn,STATISFACTION_GUID a,CREATEDDATE b,CUSTOMER_GUID c,event_guid d ,case when  PHONENO not in(select PHONENO from wmsk_statisfaction where CREATEDDATE>= sysdate-2 and TASKSTATUS=2) and PHONENO not in (select Documentto from DOCUMENTOUT where CREATEDDATE>= sysdate-2 and TASKSTATUS=2)  then 1 else 2 end flag from wmsk_statisfaction where STATISFACTION1 in('3','4') and TASKSTATUS=0 UNION ALL select ROW_NUMBER() OVER(PARTITION BY Documentto ORDER BY CREATEDDATE asc) rn,OBJECTIVE_guid a,CREATEDDATE b,CUSTOMER_GUID c,OBJECTIVE_guid d ,case when  Documentto not in( select Documentto from DOCUMENTOUT where CREATEDDATE>= sysdate-2 and TASKSTATUS=2) and Documentto not in(select PHONENO from wmsk_statisfaction where CREATEDDATE>= sysdate-2 and TASKSTATUS=2) then 1 else 2 end flag from DOCUMENTOUT dc where DOCUMENTPATH2 in('3','4') and TASKSTATUS=0  and DC.CREATEDDATE>to_date('2021-01-28 00:00:00','yyyy-mm-dd hh24:mi:ss')) w left join event e on  e.EVENT_GUID=w.d left join TABCCALSUM ta on ta.relation_id=e.event_guid left join objective o on e.EVENT_GUID=o.EVENT_GUID where w.rn = 1 and w.b<= sysdate-4/24 ";
				def guid="";
				def customer_guid="";
				def event_guid="";
				def objective_guid="";
				def objguid="";
				def list11=eliteBean.chaxun_sql(querysql11,"dataSource");
				log.debug("list11-------------------------------"+list11);
				for(def k=0;k<list11.size;k++){
					def map11=list11[k];
					def v_guid=map11.get("guid");	  
					def v_customer_guid=map11.get("customer_guid");
					def v_event_guid=map11.get("event_guid");
					def v_objective_guid=map11.get("objective_guid");
					def v_objguid=map11.get("objguid");
					def v_flag=map11.get("flag");
					log.debug("v_guid---v_guid-----v_guid----"+v_guid);
					log.debug("v_objective_guid---v_objective_guid-----v_objective_guid----"+v_objective_guid);
					log.debug("v_objguid---v_objguid-----v_objguid----"+v_objguid);
					log.debug("v_flag---v_flag-----v_flag----"+v_flag);
					if(v_flag==1){
						//生成 objective
						def updatesql26="insert into objective (OBJECTIVE_GUID,EVENT_GUID,PREOBJECTIVE_GUID, OBJECTIVETYPE_ID, HANDLEGROUP_ID,PRIORITY_ID,EXPIREDDATE,CUSTOMER_GUID,OBJECTIVESTATUS,FIRSTCONTACTDATE,LASTCONTACTDATE,CREATEDDATE,CREATEDBY,WORKORDERFRAME_ID,OBJECTIVESUBSTATUS,MAP_ID,CURSTEP_ID_MAP,if_hftask)select '"+v_objguid+"','"+v_event_guid+"','"+v_objective_guid+"','USZP59','ORG016','NORMAL',sysdate,'"+v_customer_guid+"','OPEN',sysdate, sysdate,sysdate,HANDLEBY_ID,'Y0D49L','OPEN','Y0D49L','5543RD','1' from event where event_guid='"+v_event_guid+"'";
						def updatesqlresult26=eliteBean.update(updatesql26,"dataSource");
						log.debug("updatesqlresult26:"+updatesqlresult26);
						
						//生成质检任务 elitetask 
						def updatesql27="insert into elitetask (ELITETASK_GUID, OBJECTIVE_GUID, OBJECTIVETYPE_ID, EXPECTSTARTTIME,OBSTATUS,PRIORITY, HANDLEGROUP_ID,CREATEDBY, CREATEDDATE,CUSTOMER_GUID,CURSTEPSTATUS,CURSTEP_ID_MAP,MAP_ID,OBJECTIVESUBSTATUS,ELITETASKSTATUS, OBFLAG,curstep_id) select sysguid,'"+v_objguid+"','USZP59',sysdate,'OPEN','NORMAL','ORG016',HANDLEBY_ID,sysdate,'"+v_customer_guid+"','OPEN', '5543RD','Y0D49L','OPEN','OPEN','1','5543RD' FROM event where event_guid='"+v_event_guid+"'";
						def updatesqlresult27=eliteBean.update(updatesql27,"dataSource");
						log.debug("updatesqlresult27:"+updatesqlresult27);   

						//生成回访任务 elitetask 
						def updatesql30="insert into elitetask (ELITETASK_GUID, OBJECTIVE_GUID, OBJECTIVETYPE_ID, EXPECTSTARTTIME,OBSTATUS,PRIORITY, HANDLEGROUP_ID,CREATEDBY, CREATEDDATE,CUSTOMER_GUID,CURSTEPSTATUS,CURSTEP_ID_MAP,MAP_ID,OBJECTIVESUBSTATUS,ELITETASKSTATUS, OBFLAG,curstep_id) select sysguid,'"+v_objguid+"','USZP59',sysdate,'OPEN','NORMAL','ORG016',HANDLEBY_ID,sysdate,'"+v_customer_guid+"','OPEN', 'J0KWTM','Y0D49L','OPEN','OPEN','1','J0KWTM' FROM event where event_guid='"+v_event_guid+"'";
						def updatesqlresult30=eliteBean.update(updatesql30,"dataSource");
						log.debug("updatesqlresult30:"+updatesqlresult30);  		
							
						//更新 event 关联回访的 hf_objective_guid
						log.debug("更新event关联回访的hf_objective_guid");
						def updatesql28="update event set hf_objective_guid='"+v_objguid+"' where EVENT_GUID='"+v_event_guid+"'";
						def updatesqlresult28=eliteBean.update(updatesql28,"dataSource");
						log.debug("updatesqlresult28:"+updatesqlresult28);		

						//生成不满意回访任务后更新满意度表 状态
						log.debug("不满意已生成回访更新状态");
						def updatesql29="update wmsk_statisfaction set TASKSTATUS='2',OBJECTIVE_GUID='"+v_objguid+"' where event_guid='"+v_event_guid+"'";
						def updatesqlresult29=eliteBean.update(updatesql29,"dataSource");
						def updatesqlresult291=eliteBean.update("update DOCUMENTOUT set TASKSTATUS='2',ACCOUNT_GUID='"+v_objguid+"' where OBJECTIVE_guid='"+v_event_guid+"'","dataSource");
						log.debug("updatesqlresult29:"+updatesqlresult29);
					}else if(v_flag==2){
						def updatesql32="insert into objective (OBJECTIVE_GUID,EVENT_GUID,PREOBJECTIVE_GUID, OBJECTIVETYPE_ID, HANDLEGROUP_ID,PRIORITY_ID,EXPIREDDATE,CUSTOMER_GUID,OBJECTIVESTATUS,FIRSTCONTACTDATE,LASTCONTACTDATE,CREATEDDATE,CREATEDBY,WORKORDERFRAME_ID,OBJECTIVESUBSTATUS,MAP_ID,CURSTEP_ID_MAP)select '"+v_objguid+"','"+v_event_guid+"','"+v_objective_guid+"','USZP59','ORG016','NORMAL',sysdate,'"+v_customer_guid+"','OPEN',sysdate, sysdate,sysdate,HANDLEBY_ID,'Y0D49L','OPEN','Y0D49L','ZMJPUB' from event where event_guid='"+v_event_guid+"'";
						def updatesqlresult32=eliteBean.update(updatesql32,"dataSource");
						log.debug("updatesqlresult32:"+updatesqlresult32);
						
						//生成质检任务 elitetask 
						def updatesql33="insert into elitetask (ELITETASK_GUID, OBJECTIVE_GUID, OBJECTIVETYPE_ID, EXPECTSTARTTIME,OBSTATUS,PRIORITY, HANDLEGROUP_ID,CREATEDBY, CREATEDDATE,CUSTOMER_GUID,CURSTEPSTATUS,CURSTEP_ID_MAP,MAP_ID,OBJECTIVESUBSTATUS,ELITETASKSTATUS, OBFLAG,curstep_id) select sysguid,'"+v_objguid+"','USZP59',sysdate,'OPEN','NORMAL','ORG016',HANDLEBY_ID,sysdate,'"+v_customer_guid+"','OPEN', 'ZMJPUB','Y0D49L','OPEN','OPEN','0','ZMJPUB' FROM event where event_guid='"+v_event_guid+"'";
						def updatesqlresult33=eliteBean.update(updatesql33,"dataSource");
						log.debug("updatesqlresult33:"+updatesqlresult33);   
							
						//更新 event 关联回访的 hf_objective_guid
						log.debug("更新event关联回访的hf_objective_guid");
						def updatesql34="update event set hf_objective_guid='"+v_objguid+"' where EVENT_GUID='"+v_event_guid+"'";
						def updatesqlresult34=eliteBean.update(updatesql34,"dataSource");
						log.debug("updatesqlresult34:"+updatesqlresult34);		

						//生成不满意回访任务后更新满意度表 状态
						log.debug("不满意已生成回访更新状态");
						def updatesql35="update wmsk_statisfaction set TASKSTATUS='2',OBJECTIVE_GUID='"+v_objguid+"' where event_guid='"+v_event_guid+"'";
						def updatesqlresult35=eliteBean.update(updatesql35,"dataSource");
						def updatesqlresult351=eliteBean.update("update DOCUMENTOUT set TASKSTATUS='2',ACCOUNT_GUID='"+v_objguid+"' where OBJECTIVE_guid='"+v_event_guid+"'","dataSource");
						log.debug("updatesqlresult35:"+updatesqlresult35);

					}

				}
			}
			
		}
	}
	
	public static String doselete(String policyno,String phone,EliteBean eliteBean,String cname,String charset,int timeout,int enableSSLflag){	
		JSONObject josnbody = new JSONObject();
		josnbody.put("username","LDTP");
		josnbody.put("password","a1e9173fc8090a220c27a33b951f8f7c");
		josnbody.put("policyno",policyno);
		josnbody.put("clientname","");
		josnbody.put("mobile","");
		Map headMap=new HashMap(); //设置头文件
		headMap.put("Content-Type","application/json");
		def url="http://ecif.edhic.com/ecif/clientQueryAnswered/clientFlagToNgs";
		try{
			def msgjson = Util.doHttpPostUseHead(url,JSONObject.fromObject(josnbody).toString(),charset,timeout,enableSSLflag,headMap);
			log.debug("----客户等级查询数据--------"+phone);
			log.debug("----msgjson--------"+msgjson);
			JSONObject obj = JSONObject.fromObject(msgjson);
			def code=obj.get("code");
			def resulterror;
			if(code!= 1000){
				resulterror="2"
				return  resulterror;
			}else{
				def custClass = obj.get("data").get("custClass");
				def clientType = obj.get("data").get("clientType");
				if("VIP五星客户".equals(custClass)||"VIP五星客户-优质".equals(custClass)||"VIP五星客户-关键".equals(custClass)){
					resulterror=eliteBean.chaxun_sql("select customer_guid from(select customer_guid from CUSTOMER c  where mobile= '"+phone+"' and stringfield18 ='"+policyno+"' order by MODIFIEDDATE desc) where rownum=1","dataSource");
					if(resulterror.size()>0){
						def listtemp=resulterror[0];
						def guid = listtemp.get("customer_guid");
						eliteBean.update("update customer set fax = '"+custClass+"', homepage ='"+clientType+"' where customer_guid = '"+guid+"'","dataSource");
						return  guid;
					}else{
						def cguid=Util.getGuid();
						eliteBean.update("insert into customer(CUSTOMER_GUID,customertype_id,CUSTOMERNAME,MOBILE,createddate,createdby,MODIFIEDDATE,MODIFIEDBY,fax,homepage,stringfield18)values('"+cguid+"','KFjoin','"+cname+"','"+phone+"',sysdate,'SELITE',sysdate,'SELITE','"+custClass+"','"+clientType+"','"+policyno+"')","dataSource");
						return  cguid;
					}
				}else{
					resulterror="2"
					return  resulterror;
				}
			}
		}catch(Exception e){
			log.debug(e);
		}	
	}
}
	
	
	

